#include <cstdio>


#define SPACE ' '
#define NEWLINE '\n'
#define COLUMNS 25


inline int count_line_spaces ()
{
	int r, c;

	r = 0;
	while ((c = getchar ()) != NEWLINE)
		r += (c == SPACE);

	return r;
}


inline int spaces_after_contact (int n)
{
	int s, m, c;

	s = 0;
	m = COLUMNS;

	for (int i = 0; i < n; ++i)
	{
		c = count_line_spaces ();
		s += c;
		if (c < m)
			m = c;
	}

	s -= m * n;

	return s;
}


int main ()
{
	int n;

	while (scanf ("%d ", &n), n)
	{
		printf("%d\n", spaces_after_contact (n));
	}

	return 0;
}